var addData = function (tableName, data) {
    return dao.add(tableName, JSON.stringify(data));
}

var updateData = function (tableName, id, data) {
    var rows = dao.update(tableName, id, JSON.stringify(data));
    return rows;
}

var deleteData = function (tableName, id) {
    var isOK = dao.delete(tableName, id);

    return isOK;
}

var pageList = function (tableName, data) {
    var pageresult = dao.pagelist(tableName, JSON.stringify(data))

    return JSON.parse(pageresult);
}

var getData = function (tableName, id) {
    var item = dao.get(tableName, id);

    return JSON.parse(item);
}

var userlogin = function (username, password) {
    var result = user.login(username, password);

    return JSON.parse(result);
}

var userlogout = function(){
    user.logout();
}
var userlogstart = function(appname,modulename,itemname){
    var result = user.logstart(appname,modulename,itemname);
    return JSON.parse(result);
}
var userlogend = function(actionidstring){
    user.logend(actionidstring);
   
}
var userlogendwithresult = function(actionidstring,scores,result){
    user.logendwithresult(actionidstring,scores,result);
   
}

var adminadduser = function(userid,username,pwd)
{
    var result = user.adduser(userid,username,pwd);
    return JSON.parse(result);
}
var adminaddusermore = function(userid,username,pwd,age,cage,dept,sex,remarks)
{
    var result = user.addusermore(userid,username,pwd,age,cage,dept,sex,remarks);
    return JSON.parse(result);
}

var adminupdateusermore = function(userid,username,age,cage,dept,sex,remarks)
{
    var result = user.updateusermore(userid,username,age,cage,dept,sex,remarks);
    return JSON.parse(result);
}
var adminremoveuser = function(userid)
{
    var result = user.removeuser(userid);
    return JSON.parse(result);
}
var adminpassworduser = function(userid,pwd)
{
    var result = user.passworduser(userid,pwd);
    return JSON.parse(result);
}
var userchangpassword = function(pwd,oldpwd)
{
    var result = user.changpassword(pwd,oldpwd);
    return JSON.parse(result);
}
var exit = function () {
    js.exit();
}

var showdevtools = function(){
    js.showdevtools();
}

var reloadPage = function(){
    js.reload();
}

var resourcelist = function(sub)
{
    var result = res.resourcelist(sub);

    return JSON.parse(result);
}

var resourcelistwithsubitems = function(sub)
{
    var result = res.resourcelistwithsubitems(sub);

    return JSON.parse(result);
}
var resource_geturldata = function(filename){
    return res.geturldata(filename);
}
var openevalute = function(){
    exe.openevalute();
}
var openinterfere = function(){
	exe.openinterfere();
}

var printdoc =function(actionidstring){
    
    exe.printdoc(actionidstring);
}

var userlogreport = function(actionidstring){
    var result = user.logreport(actionidstring);
    return JSON.parse(result);
}
var user_report_person = function(userid,starttime,endtime){
	var result = user.report_person(userid,starttime,endtime);
	return JSON.parse(result);
}
var user_report_depart = function(starttime,endtime){
	var result = user.report_depart(starttime,endtime);
	return JSON.parse(result);
}
var user_finger_login = function(){
    var result = user.getcache();
    return JSON.parse(result);
}
var user_finger_clear = function(){
    var result = user.clearcache();
    return JSON.parse(result);
}
var user_finger = function(){
    user.userfinger();
}
var remind_set = function(){
	remind.set();
}
var remind_play = function(json,title){
    remind.playwithtitle(json,title);
}
var Base64 = {
    encode(str) {
        // first we use encodeURIComponent to get percent-encoded UTF-8,
        // then we convert the percent encodings into raw bytes which
        // can be fed into btoa.
        return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
            function toSolidBytes(match, p1) {
                return String.fromCharCode('0x' + p1);
            }));
    },
    decode(str) {
        // Going backwards: from bytestream, to percent-encoding, to original string.
        return decodeURIComponent(atob(str).split('').map(function (c) {
            return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
        }).join(''));
    }
};

document.onkeydown = function (event) {
    var e = event || window.event || arguments.callee.caller.arguments[0];

/*    if(e)
        console.log(e.keyCode); */

    if (e && e.keyCode == 27) { // 按 Esc 

        //退出
        exit();
    }

    if (e && e.keyCode == 116) { // 按 F5 

        //刷新页面
        reloadPage();
    }

    if (e && e.keyCode == 123) { // F12 键

        //弹出开发工具
        showdevtools();
    }

};
